<template>
  <div class="lang">
    <el-dropdown @command="changeLang">
      <span class="el-dropdown-link">
        <svg-icon icon-class="language" class="lang-icon" />
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item :disabled="$i18n.locale == 'en'" command="en"
          >English</el-dropdown-item
        >
        <el-dropdown-item :disabled="$i18n.locale == 'zh'" command="zh"
          >中文</el-dropdown-item
        >
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
import Cookies from 'js-cookie'
export default {
  methods: {
    changeLang (lang) {
      // console.log(cmd)
      //   设置给i18n插件
      this.$i18n.locale = lang
      // 存储到本地cookies
      Cookies.set('lang', lang)
      // 提示
      this.$message.success('修改语言成功')
      // 刷新路由
      this.$router.go(0)
    }
  }
}
</script>

<style></style>
